{include file="common/comm_header" /}

<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="L_class_title" class="layui-form-label">
                <span class="x-red">*</span>
                所属分类：
            </label>
            <div class="layui-input-block">
                <select name="class_id" id="L_class_title" lay-verify="">
                    {volist name="classDataList" id="vo"}
                    <option value="{$vo.assort_id}">{$vo.assort_title}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_web_title" class="layui-form-label">
                <span class="x-red">*</span>
                网站标题：
            </label>
            <div class="layui-input-block">
                <input type="text" id="L_web_title" name="web_title" value="" required="" lay-verify="web_title"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                网站标题不能为空
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_web_url" class="layui-form-label">
                <span class="x-red">*</span>
                网站URL：
            </label>
            <div class="layui-input-block">
                <input type="text" id="L_web_url" name="web_url" value="" required="" lay-verify="web_url"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                网站URL不能为空
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_web_description" class="layui-form-label">
                网站描述：
            </label>
            <div class="layui-input-block">
                <textarea style="resize: none;"  id="L_web_description" name="web_description" placeholder="可不写，也可随便写写" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_web_sort" class="layui-form-label">
                网站排序：
            </label>
            <div class="layui-input-block">
                <input type="text" id="L_web_sort" name="web_sort" value="0" required="required" lay-verify="web_sort"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                -999到999区间的任意两位小数
            </div>
        </div>

        <!--提交按钮-->
        <div class="layui-form-item">
            <label for="L_web_sort" class="layui-form-label">
            </label>
            <button id="addAssort"  class="layui-btn" lay-filter="web-add" lay-submit="">
                添加
            </button>
        </div>
    </form>
</div>
<script type="text/javascript" src="/static/common/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin//lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/static/admin//js/xadmin.js"></script>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="/static/common/js/html5.min.js"></script>
<script src="/static/common/js/respond.min.js"></script>
<![endif]-->
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            web_title: function(value){
                var valLen = value.length;
                if(valLen < 1){
                    return '网站标题不能为空啊';
                }
                if(valLen >40){
                    return '网站标题也太长了吧，不要超过40个字符';
                }
            }
            ,web_url: function(value){
                var valLen = value.length;
                if(valLen < 1){
                    return '网站URL不能为空啊';
                }
                if(valLen >200){
                    return '网站URL也太长了吧，不要超过200个字符';
                }
            }
            ,web_sort: function(value){
                var sortLen = value.length;
                if(sortLen == 0){
                    return  '填个排序吧';
                }
                var reg = /^-?\d+\.?\d{0,2}$/;
                if(!(reg.test(value))){
                    return  '排序只能是两位小数的数字啊';
                }
                if(value < -999 || value > 999){
                    return '排序只能在999到-999的区间';
                }
            }
        });

        //监听提交
        form.on('submit(web-add)', function(data){
            ///提交修改
            $('#addAssort').attr('disabled',true);
            $.ajax({
                url:'/{$Think.ADMIN_ROUT_PREFIX}/web-add/'+Math.random(),
                timeout : 1000,
                type : 'post',
                data :{class_id:parseFloat(data.field.class_id),web_title:data.field.web_title,web_url:data.field.web_url,web_description:data.field.web_description,web_sort:data.field.web_sort},
                async: false,
                dataType:'json',
                success:function(data){
                    var testJson = $.parseJSON(data);
                    if(testJson.status == 0){
                        layer.alert(testJson.msg, {
                            icon: 6,
                            time: 1000,
                            closeBtn:0,
                            end:function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                            }
                        });
                    }else if(testJson.status == 2){
                        layer.alert(testJson.msg, {
                            icon: 5,
                            time: 2000
                        });
                        $('#addAssort').attr('disabled',false);
                        return false;
                    }else{
                        layer.alert('出现异常', {
                            icon: 5,
                            time: 2000
                        });
                        $('#addAssort').attr('disabled',false);
                        return false;
                    }
                },
                error:function(){
                    layer.alert('出现异常，建议刷新页面。', {
                        icon: 5,
                        time: 2000
                    });
                    $('#addAssort').attr('disabled',false);
                    return false;
                }
            });

            return false;
        });


    });
</script>
</body>

{include file="common/comm_bottom" /}